package com.wzl.controller;

import com.wzl.common.MessageConst;
import com.wzl.common.entity.Result;
import com.wzl.common.pojo.UserPojo;
import com.wzl.service.MpBasicUsageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Mp基本用法
 *
 * @author weizhongli
 * @since 2022-09-10 16:07
 */
@Controller
@ResponseBody
public class MpBasicUsageController {

    @Resource
    private MpBasicUsageService mpBasicUsageService;

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @RequestMapping("mpBasicSelect/{id}")
    public Result getUserById(@PathVariable("id") Integer id) {
        UserPojo userPojo;
        try {
            userPojo = mpBasicUsageService.getUserById(id);
        } catch (Exception e) {
            return new Result(false, e.getMessage());
        }
        return new Result(true, MessageConst.ACTION_SUCCESS, userPojo);
    }

    /**
     * 根据id修改
     * @param id
     * @return
     */
    @RequestMapping("mpBasicUpdate/{id}")
    public Result UpdateUserById(@PathVariable("id") Integer id) {
        try {
            int i = mpBasicUsageService.UpdateUserById(id);
        } catch (Exception e) {
            return new Result(false, e.getMessage());
        }
        return new Result(true, MessageConst.UPDATE_BY_ID_SUCCESS);
    }

    /**
     * 新增记录
     * @param
     * @return
     */
    @RequestMapping("mpBasicInsert")
    public Result InsertUserById() {
        try {
            int i = mpBasicUsageService.InsertUserById();
        } catch (Exception e) {
            return new Result(false, e.getMessage());
        }
        return new Result(true, MessageConst.INSERT_SUCCESS);
    }

}